package edu.gyc.testthread;

import java.util.Random;

public class MainThreadWait1 {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName()+":发布任务，不做完任务，不下班...");
     Thread thread1=   new Thread(new Runnable() {
            @Override
            public void run() {

                System.out.println(Thread.currentThread().getName()+":开始抓小偷");
                Random random = new Random();
                for (int i = 1; i <= 10; i++) {
                    try {
                        Thread.sleep(random.nextInt(3) * 1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+":抓到小偷"+i);
                }
                System.out.println(Thread.currentThread().getName()+":抓小偷任务完成");
            }
        },"便衣刑警");

     Thread thread2=   new Thread(new Runnable() {
            @Override
            public void run() {

                System.out.println(Thread.currentThread().getName()+":开始抓违章");
                Random random = new Random();
                for (int i = 1; i <= 10; i++) {
                    try {
                        Thread.sleep(random.nextInt(3) * 1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+":抓到违章"+i);
                }
                System.out.println(Thread.currentThread().getName()+":抓违章任务完成");
            }
        },"交通警察");

     thread1.start();
     thread2.start();
        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+":警察们总算完成任务了，我也可以下班了。");
    }


}
